package com.likersai.opon.system.aop;

import com.likersai.opon.pojo.bo.EntityBO;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * DAO切面
 *
 * @author sun.ye
 * @since 2022-05-27 10:39
 */
@Slf4j
@Aspect
@Component
public class DaoAspect {
    
    @Pointcut("execution(* com.likersai.opon.dao.*Mapper.update*(..))")
    public void pointUpdate(){}
    
    @Pointcut("execution(* com.likersai.opon.dao.*Mapper.insert*(..))")
    public void pointInsert(){}
    
    @Before("pointUpdate() ||  pointInsert() ")
    public void setBaseEntityInfo(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        if (args == null){
            return;
        }
        
        for (Object arg : args) {
            if (arg instanceof EntityBO){
                EntityBO entityBO = (EntityBO) arg;
                if (entityBO.hasNoTime()){
                    entityBO.initDate();
                }
            }
        }
    }
    
}